# -*- coding: UTF-8 -*-
from qiniu import Auth, put_file
import time
import os

accessKey="ak9AVHKsroHmrJuSDmoV30HrlmAB-XLoipX8-hvX"
secretKey="E7eAOUHEfcpB0lJipFbepjLpxd1PFY5i6jBN50rB"
bucket_name='zziahui'
q=Auth(access_key=accessKey, secret_key=secretKey);
baseUrl="http://7xsegb.com1.z0.glb.clouddn.com/"

def upload(filename):
    key=str(int(time.time()*100))
    #生成上传 Token，可以指定过期时间等
    token = q.upload_token(bucket_name, key, 3600)
    #要上传文件的本地路径
    filepath=os.path.abspath("img.jpg")
    print filepath
    ret, info = put_file(token, key, filepath)
    if 200 == info.status_code:
        return baseUrl + ret['key']
    return ""


print upload("img.jpg")
